package edu.xidian.sselab.cloudcourse.controller;

import edu.xidian.sselab.cloudcourse.domain.test4_entity;
import edu.xidian.sselab.cloudcourse.repository.test4_Repository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class test4_controller {

    @Autowired
    private test4_Repository test4_repository;

    @RequestMapping("/test4")
    public String test4_try(Model model){ //要求4的controller
        model.addAttribute("title", "轿车 SUV MPV各月总销量走势");
        return "test4"; //跳转到test1页面
    }

    @RequestMapping("/test20")
    public @ResponseBody
    Map test4_try2() throws IOException { //要求4的controller

        String level = "SUV"; //车级别，SUV

        String start_time = "201907"; //开始时间

        String end_time = "202006"; //结束时间

        List<test4_entity> recordList1 = test4_repository.find(level,start_time,end_time); //根据要求查找数据
        List<test4_entity> recordList2 = test4_repository.find("MPV",start_time,end_time); //根据要求查找数据
        List<test4_entity> recordList3 = test4_repository.find("紧凑型车",start_time,end_time); //根据要求查找数据
        Map<String,List> map=new HashMap<>();
        map.put("SUV",recordList1);
        map.put("MPV",recordList2);
        map.put("紧凑型车",recordList3);


        System.out.println("以下是201907到202006的所有车型的销售数据：");

        System.out.println(map);
        return map;
    }
}
